import 'dart:convert' show json;

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

List<String> castList(data) {
  if (data != null) {
    return List.castFrom(data);
  }
  return null;
}

class UserTask {
  UserTask({
    this.userId,
    this.taskArray,
    this.task,
    this.parallel,
    this.dealWith,
    this.removeTag,
  });

  factory UserTask.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : UserTask(
          userId: asT<String>(jsonRes['userId']),
          taskArray: castList(jsonRes['taskArray']),
          task: asT<String>(jsonRes['task']),
          parallel: asT<bool>(jsonRes['parallel']),
          dealWith: asT<bool>(jsonRes['dealWith']),
          removeTag: asT<bool>(jsonRes['removeTag']),
        );

  String userId;
  List<String> taskArray;
  String task;
  bool parallel;
  bool dealWith;
  bool removeTag;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'userId': userId,
        'taskArray': taskArray,
        'task': task,
        'parallel': parallel,
        'dealWith': dealWith,
        'removeTag': removeTag,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}
